home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2006 May
/
PCWMAY06.iso
/
Software
/
Freeware
/
First Page 2006 3.00
/
fp2006-final-3.00-setup.exe
/
{app}
/
Iscripts
/
Forms Misc
/
bitmap-object.izs
< prev
next >
Wrap
Text File
|
2005-09-28
|
6KB
|
230 lines
<!NOWIZARD>
<!TITLE>Bitmap & Object Script
<!/TITLE>
<!DESCRIPTION>This script shows how to use bitmasking to store values in a single variable and how to use objects with JavaScript. <!/DESCRIPTION>
<!CATEGORY>Forms<!/CATEGORY>
<!SCRIPT>
<!-- START OF SCRIPT -->
<!-- HOW TO INSTALL BITMAP & OBJECT SCRIPT:
1. Copy code into the HEAD section of document
2. Put last coding into the BODY section of document -->
<!-- STEP ONE: Add code into HEAD section of document -->
<HEAD>
<!-- Original: Fernando Rios (test118@hotmail.com) -->
<!-- Web Site: http://www15.brinkster.com/hxedit -->
<script>
//these will be the bitmask values. they must be powers of 2
var ram128=1;
var ram256=2;
var ram512=4;
var cpu1000=64;
var cpu2000=128;
var cpu3000=256;
var hd20=2048;
var hd40=4096;
var hd80=8192;
//====this will be our 'computer' object===
function Computer (f){
var features=f;//private variable of computer. stores the features
/***priviliged methods of Computer. can be accessed from the outside but
also has access to private variable 'features'*/
this.getFeatures=function(){
var ret="";//return string
/*this is where the bitmask operations occur
it will do a bitwise comparison of the features value with the
value that were testing against. if the result is equal to the value
were testing, the value was set. remember to use a bitwise & instead of &&*/
if((features & cpu1000) == cpu1000)
ret+="CPU: 1Ghz\n";
if((features & cpu2000) == cpu2000)
ret+="CPU: 2Ghz\n";
if((features & cpu3000) == cpu3000)
ret+="CPU: 3Ghz\n";
if((features & ram128) == ram128)
ret+="RAM: 128MB\n";
if((features & ram256) == ram256)
ret+="RAM: 256MB\n";
if((features & ram512) == ram512)
ret+="RAM: 512MB\n";
if((features & hd20) == hd20)
ret+="HD : 20GB\n";
if((features & hd40) == hd40)
ret+="HD : 40GB\n";
if((features & hd80) == hd80)
ret+="HD : 80GB\n";
return ret;
};
this.setFeatures=function (feat){
this.features=feat
};
//**
}
//=========================================
</script>
</HEAD>
<!-- STEP TWO: Add code into BODY section of document -->
<BODY>
<!-- Original: Fernando Rios (test118@hotmail.com) -->
<!-- Web Site: http://www15.brinkster.com/hxedit -->
<form name="theForm">
Select desired features<br>
CPU:
<select style="width=125" name="cboCPU">
<option value=64>1Ghz (1000Mhz)</option>
<option value=128>2Ghz (2000Mhz)</option>
<option value=256>3Ghz (3000Mhz)</option>
</select><br>
RAM:
<select style="width=125" name="cboRAM">
<option value=1>128MB</option>
<option value=2>256MB</option>
<option value=4>512MB</option>
</select><br>
HD:
<select style="width=125" name="cboHD">
<option value=2048>20GB</option>
<option value=4096>40GB</option>
<option value=8192>80GB</option>
</select><br>
<!--remember to use | (bitwise OR) when setting the bitmask-->
<input type="button" value="1. set attributes" onclick="Javascript:aComputer=new Computer(cboCPU.options[cboCPU.selectedIndex].value | cboRAM.options[cboRAM.selectedIndex].value | cboHD.options[cboHD.selectedIndex].value);">
<input type="button" value="2. get attributes" onclick="Javascript:alert(aComputer.getFeatures());")<br>
<input type="reset" value="3. Reset">
</form>
<!-- END OF SCRIPT -->
<!/SCRIPT>
<!PREVIEW>
<!-- START OF SCRIPT -->
<!-- HOW TO INSTALL BITMAP & OBJECT SCRIPT:
1. Copy code into the HEAD section of document
2. Put last coding into the BODY section of document -->
<!-- STEP ONE: Add code into HEAD section of document -->
<HEAD>
<!-- Original: Fernando Rios (test118@hotmail.com) -->
<!-- Web Site: http://www15.brinkster.com/hxedit -->
<script>
//these will be the bitmask values. they must be powers of 2
var ram128=1;
var ram256=2;
var ram512=4;
var cpu1000=64;
var cpu2000=128;
var cpu3000=256;
var hd20=2048;
var hd40=4096;
var hd80=8192;
//====this will be our 'computer' object===
function Computer (f){
var features=f;//private variable of computer. stores the features
/***priviliged methods of Computer. can be accessed from the outside but
also has access to private variable 'features'*/
this.getFeatures=function(){
var ret="";//return string
/*this is where the bitmask operations occur
it will do a bitwise comparison of the features value with the
value that were testing against. if the result is equal to the value
were testing, the value was set. remember to use a bitwise & instead of &&*/
if((features & cpu1000) == cpu1000)
ret+="CPU: 1Ghz\n";
if((features & cpu2000) == cpu2000)
ret+="CPU: 2Ghz\n";
if((features & cpu3000) == cpu3000)
ret+="CPU: 3Ghz\n";
if((features & ram128) == ram128)
ret+="RAM: 128MB\n";
if((features & ram256) == ram256)
ret+="RAM: 256MB\n";
if((features & ram512) == ram512)
ret+="RAM: 512MB\n";
if((features & hd20) == hd20)
ret+="HD : 20GB\n";
if((features & hd40) == hd40)
ret+="HD : 40GB\n";
if((features & hd80) == hd80)
ret+="HD : 80GB\n";
return ret;
};
this.setFeatures=function (feat){
this.features=feat
};
//**
}
//=========================================
</script>
</HEAD>
<!-- STEP TWO: Add code into BODY section of document -->
<BODY>
<!-- Original: Fernando Rios (test118@hotmail.com) -->
<!-- Web Site: http://www15.brinkster.com/hxedit -->
<form name="theForm">
Select desired features<br>
CPU:
<select style="width=125" name="cboCPU">
<option value=64>1Ghz (1000Mhz)</option>
<option value=128>2Ghz (2000Mhz)</option>
<option value=256>3Ghz (3000Mhz)</option>
</select><br>
RAM:
<select style="width=125" name="cboRAM">
<option value=1>128MB</option>
<option value=2>256MB</option>
<option value=4>512MB</option>
</select><br>
HD:
<select style="width=125" name="cboHD">
<option value=2048>20GB</option>
<option value=4096>40GB</option>
<option value=8192>80GB</option>
</select><br>
<!--remember to use | (bitwise OR) when setting the bitmask-->
<input type="button" value="1. set attributes" onclick="Javascript:aComputer=new Computer(cboCPU.options[cboCPU.selectedIndex].value | cboRAM.options[cboRAM.selectedIndex].value | cboHD.options[cboHD.selectedIndex].value);">
<input type="button" value="2. get attributes" onclick="Javascript:alert(aComputer.getFeatures());")<br>
<input type="reset" value="3. Reset">
</form>
<!-- END OF SCRIPT -->
<!/PREVIEW>
<!RELATED>NONE<!/RELATED>